import {
  getHistoryEventCountApi,
  getHistoryEventCountDetailApi,
  getHistoryFlightCountDetailApi
} from '@/services/faultMonitoring';

export default {
  namespaced: true,
  state: {
    historyFault: [],
    faultLoading: false,
    historyEventCountDetail: [],
    getHistoryEventCountDetailLoading: false,
    detailsVisible: false,
    detailsVisible2: false,
    historyFlightCountDetail: [],
    getHistoryFlightCountDetailLoading: false
  },
  mutations: {
    setState(state, { key, payload }) {
      state[key] = payload;
    }
  },
  actions: {
    async getHistoryEventCount({ commit, state, dispatch }, params) {
      commit('setState', { key: 'faultLoading', payload: true });
      const rep = await getHistoryEventCountApi(params);
      commit('setState', { key: 'historyFault', payload: rep.data });
      commit('setState', { key: 'faultLoading', payload: false });
    },
    async getHistoryEventCountDetail({ commit, state }, params) {
      commit('setState', { key: 'getHistoryEventCountDetailLoading', payload: true });
      const rep = await getHistoryEventCountDetailApi(params);
      commit('setState', { key: 'historyEventCountDetail', payload: rep.data });
      commit('setState', { key: 'getHistoryEventCountDetailLoading', payload: false });
    },
    async getHistoryFlightCountDetail({ commit, state }, params) {
      commit('setState', { key: 'getHistoryFlightCountDetailLoading', payload: true });
      const rep = await getHistoryFlightCountDetailApi(params);
      commit('setState', { key: 'historyFlightCountDetail', payload: rep.data });
      commit('setState', { key: 'getHistoryFlightCountDetailLoading', payload: false });
    }
  }
};
